/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：LockedScreen.java <br>
 * 创建时间：2014-8-1 上午9:31:42 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.ui;

import android.util.SparseArray;

import lostland.gmud.exv2.ui.core.FullScreen;

/**
 * 类名：LockedScreen <br>
 * 说明：显示一行文字，玩家不能手动退出的界面
 *
 * @author 12548
 */
public class LockedScreen extends FullScreen {

	private static final SparseArray<String> locks = new SparseArray<>();

	public static void lock(int lockid, String text) {
		if (lockid < 0) {
			lock(text);
			return;
		}
		LockedScreen ls;
		if (getGame().getCurrentScreen() instanceof LockedScreen) {
			ls = (LockedScreen) getGame().getCurrentScreen();
			ls.w.text = text;
		} else {
			ls = new LockedScreen(text);
			ls.pushToGame();
		}

		locks.put(lockid, text);
	}

	public static int lock(String text) {
		int start = 9000;
		int i;
		for (i = start; locks.get(i) != null; i++) {
		}
		lock(i, text);
		return i;
	}

	public static boolean unLock(int lockid) {
		if (lockid < 0) return false;

		if (getGame().getCurrentScreen() instanceof LockedScreen) {
			LockedScreen ls = (LockedScreen) getGame().getCurrentScreen();

			locks.remove(lockid);

			if (locks.size() > 0) {
				ls.w.text = locks.valueAt(0);
				return false;
			} else {
				ls.removeFromGame();
				return true;
			}
		} else
			return false;
	}

	public static void unlockAll() {
		locks.clear();
		if (getGame().getCurrentScreen() instanceof LockedScreen) {
			getGame().getCurrentScreen().removeFromGame();
		}
	}


	AutoWindow w;

	public LockedScreen(String s) {
		super();
		w = new AutoWindow(80, 69, 160, 14, s);
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.DialogScreen#onTouchDown(int, int)
	 */
	@Override
	protected void onTouchDown(int tx, int ty) {

	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.DialogScreen#onTouchMove(int, int)
	 */
	@Override
	protected void onTouchMove(int tx, int ty) {
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.DialogScreen#onTouchUp(int, int)
	 */
	@Override
	protected void onTouchUp(int tx, int ty) {
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.DialogScreen#onClick(int, int)
	 */
	@Override
	protected void onClick(int tx, int ty) {

	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.blgframework.CScreen#present(float)
	 */
	@Override
	public void present(float deltaTime) {
		getGame().getParentScreen().present(0);
//		MapScreen.getInstance().present(0);
		w.draw();
	}


}
